﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using ZLCMS.Business;
using System.Web.Configuration;
using DotNet.Common.Command;
using ZLCMS.Business.Util;
using DotNet.Common.DataTransfers;
using DotNet.Common.DataTransfers.Config;

namespace ZLCMS.Web.SystemManage.Basics.Shop.Score
{
    public partial class ScoreCardImport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public string ConnectionString
        {
            get
            {
                return "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ViewState["file"] + ";Extended Properties=Excel 12.0 Xml;";
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Literal1.Text = "";
            string exl = Server.MapPath("~/Upload/" + DateTime.Now.Ticks + ".xls");
            FileUpload1.SaveAs(exl);
            ViewState["file"] = exl;


            Install();
        }

        protected void Install()
        {

            ExcelLoaderUtil loader = new ExcelLoaderUtil();
            loader.ConnectionString = ConnectionString;

            IList<IDictionary> list = loader.LoadSource("");
            foreach (IDictionary dic in list)
            {
                dic["RULE_ID"] = Request["RuleId"];
            }
            TargetInstaller installer = new TargetInstaller();
            TupleInstallElement element = TransfersConfig.Configuare(Server.MapPath("~/App_Data/import/score_card_transfer.xml"));

            int count = installer.Install(list, element);
            string tips = "<p>{2}_处理结果——待处理记录{0}条，已影响记录{1}条</p>";
            Literal1.Text += string.Format(tips, list.Count, count, element.Description);
        }
    }
}